// +----------------------------------------------------------------------
// | bossHongshi [鸿时互娱管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.hongshihuyu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wgh
// +----------------------------------------------------------------------
const fly=require("flyio")
module.exports = class extends think.cmswing.center {
  async __before() {
    await super.__before();
    // 判断是否登陆
    // await this.weblogin();
    if (!this.is_login) {
      // 判断浏览客户端
      if (this.isMobile) {
        // 手机端直接跳转到登录页面
        return this.redirect('/center/public/login');
      } else {
        return this.redirect('/cmswing/error/login');
      }
    }
  }
  // 我的的俱乐部
  async indexAction() {
     const club_no = this.para('club_no') || null;
    
     console.log('club_no------------------1:'+club_no);
    
//    const gameserver = this.service('cmswing/gameserver', this.ctx);
//    let clubsPromise  = think.promisify(gameserver.getclubs);
//    const clubs = await clubsPromise();
//    console.log('clubs data--------------2222----:'+JSON.stringify(clubs));
    
      const userInfo = await this.model('member').find(this.user.uid);
  //发送Get请求
      //http://127.0.0.1:5100/club?uid=7&area=niuniuBackend&cmd=queryClubDetail&club_id=100008&sign=password
	  const url='http://www.hongshihuyu.com:17100/club?uid='+(think.isEmpty(userInfo.game_id)?-1:userInfo.game_id)+'&area=niuniuBackend&cmd=queryClubByAgentId&agentId='+userInfo.proxy_id+'&sign=password';
	  
	  console.log('club index url------------------:'+url);
	  
	  fly.config.timeout=10000;
	  fly.config.parseJson=true;
	  fly.interceptors.response.use(
			    (response) => {
			        //只将请求结果的data字段返回
			        return response.data
			    },
			    (err) => {
			        //发生网络错误后会走到这里
			        //return Promise.resolve("ssss")
			    }
		)
	  let ret = await fly.get(url).catch(() => false);
      
//      var http=require('http');
//      var clublist;
//      var totalid;
//      var ret='';
//       await http.get(url,function(req,res){	
//    	  req.on('data',function(data){		
//    		  ret+=data;	
//    		});	
//    	  
//    	  req.on('end',function(){		
//    		  console.log('club ret------------------:'+ret);
//    		  let retjson = (ret === false?null:JSON.parse(ret));
//    		  console.log('retjson ret------------------:'+JSON.stringify(retjson));
//    		  clublist= (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.arr))?retjson.data.arr:[];
//    		  totalid = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.arr))?retjson.data.arr.length:0;
//    	  });
//
//     });
	console.log('ret----------------111--:'+ret);
    let retjson = (ret === false?null:JSON.parse(ret));
	let clublist= (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.arr))?retjson.data.arr:[];
	let totalid = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.arr))?retjson.data.arr.length:0;
	
    console.log('clublist------------------:'+JSON.stringify(clublist));
    console.log('totalid------------------:'+totalid);
    
    this.assign('list',clublist);
    this.assign('totalid',totalid);
	this.assign('userInfo', userInfo);
	this.assign('clubsmn', this.config('setup.CLUB_SETUP_MIN_NUM'));
    this.meta_title = '我的俱乐部';
    // 判断浏览客户端
    if (this.isMobile) {
      if (this.isAjax('get')) {
    	
        for (const v of clubdata.data.arr) {
          v.create_time = this.moment(v.create_time).format('lll');
        }
        return this.json(clubdata.data);
      } else {
        this.active = 'club/index';
        return this.display(this.mtpl());
      }
    } else {
      return this.display();
    }
  }

  /**
   * 注册俱乐部
   */
  async createAction() {
    if (this.isAjax('POST')) {
      const data = this.post();
      if (think.isEmpty(data.club_name)) {
        return this.fail('请输入俱乐部名称！');
      } else if (data.club_name.length>10){
        return this.fail('俱乐部名称太长,只能输入2-10个汉字！');
      }
      const clubsmn = this.config('setup.CLUB_SETUP_MIN_NUM');
      console.log('创建俱乐部--post data:'+JSON.stringify(data));
      // 用户
      data.user_id = this.user.uid;
      const userInfo = await this.model('member').find(this.user.uid);
      let  update =false;
      if(userInfo.card_count<clubsmn){
    	  return this.fail('您的房卡不够创建俱乐部！');
      }else{
    	  //发送Get请求
    	  const url='http://47.97.119.70:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=createClub&name="'+data.club_name+'"&card='+clubsmn+'&notice="这是一个俱乐部"&sign=password';
    	  
    	  console.log('创建俱乐部 ------------------url:'+encodeURI(url));
    	  fly.config.timeout=10000;
    	  fly.config.parseJson=true;
          fly.interceptors.response.use(
			    (response) => {
			        //只将请求结果的data字段返回
			        return response.data
			    },
			    (err) => {
			        //发生网络错误后会走到这里
			        //return Promise.resolve("ssss")
			    }
		)
    	  //let ret = await fly.get(encodeURI(url));
		  let ret = await fly.get(encodeURI(url)).catch(() => false);
		  console.log('创建俱乐部 ret------------------:'+ret);
          let retjson = (ret === false?null:JSON.parse(ret));
    	  //let retdata = JSON.parse(ret.data);
    	  //console.log('创建俱乐部 ------------------1111111:'+JSON.stringify(retjson));
    	  
    	  if(retjson!=null&&retjson.data.result==0){
    		  update = await this.model('member').where({id:data.user_id}).decrement('card_count',clubsmn);
    		//0:账户充值，1:提现,2:订单,3:充卡,4:充币,5:返利,6:奖励金币，7:奖励房卡,8:耗卡,9:耗币
		      if(update){
		    		const blog = {
		   	                 admin_id: 1,
		   	                 user_id:this.user.uid,
		   	                 type:8,
		   	                 time: new Date().valueOf(),
		   	                 amount: Number(clubsmn),
		   	                 amount_log: Number(userInfo.card_count)-Number(clubsmn),
		   	                 note: userInfo.username+'创建俱乐部:'+retjson.data.info._id+' 转入房卡 '+clubsmn+' 张'
		   	               };
		   	        await this.model('balance_log').add(blog);
					return this.success({name:'创建成功！'});
		     }else {
                  return this.fail('创建失败！');
             }
    	  }
      }
    } else {
      // 获取用户信息
//      const createTime = new Date().getTime();
//  	const timestr = createTime.toString();
//  	console.log('timestr. data---------:'+timestr);
//  	console.log('timestr.substr(5) data---------:'+timestr.substr(5));
      const userInfo = await this.model('member').find(this.user.uid);
      this.assign('userInfo', userInfo);
      this.assign('clubsmn', this.config('setup.CLUB_SETUP_MIN_NUM'));
      
      this.meta_title = '创建俱乐部';
      if (this.isMobile) {
        this.active = 'club/index';
        return this.display(this.mtpl());
      } else {
        this.display();
      }
    }
  }
  
  /**
   * 配置俱乐部
   */
  async settingAction() {
    if (this.isAjax('POST')) {
      const data = this.post();
      //dailyCard:dailyCard,
	     //warnCard:warnCard
      if (think.isEmpty(data.dailyCard)) {
        return this.fail('请输入每位成员每天最多可消耗数量！');
      } else if (think.isEmpty(data.warnCard)){
        return this.fail('请输入俱乐部房卡过低提醒数量！');
      }
      console.log('设置俱乐部--post data:'+JSON.stringify(data));
      // 用户
      data.user_id = this.user.uid;
      const userInfo = await this.model('member').find(this.user.uid);
      //发送Get请求
      //设置俱乐部--post data:{"dailyCard":"300","warnCard":"100","clubid":"10307"}

	  const url='http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id
	  +'&area=niuniuBackend&cmd=cardConsume&club_id='+data.clubid+'&dailyCard='
	  +data.dailyCard+'&warnCard='+data.warnCard+'&sign=password';
	  
	  console.log('设置俱乐部 ------------------url:'+url);
	  fly.config.timeout=10000;
	  fly.config.parseJson=true;
      fly.interceptors.response.use(
		    (response) => {
		        //只将请求结果的data字段返回
		        return response.data
		    },
		    (err) => {
		        //发生网络错误后会走到这里
		        //return Promise.resolve("ssss")
		    }
	  )
	  //let ret = await fly.get(url);
	  let ret = await fly.get(url).catch(() => false);
      
	  console.log('设置俱乐部 ret------------------:'+ret);
      let retjson = (ret === false?null:JSON.parse(ret));
	  
	  if(retjson!=null&&retjson.data.result==0){
	     return this.success({name:'设置成功！'});
	  }else {
         return this.fail('设置失败！');
      }
      
    } else {
      const club_id = this.para('id') || null;
      console.log('俱乐部 id------------------:'+club_id);
      this.assign('club_id', club_id);
      this.meta_title = '俱乐部设置';
      if (this.isMobile) {
        this.active = 'club/account/?clubid='+club_id;
        return this.display(this.mtpl());
      } else {
        this.display();
      }
    }
  }
  
  /**
   * 添加俱乐部成员
   */
  async addplayerAction() {
    if (this.isAjax('POST')) {
      const data = this.post();
      console.log('添加俱乐部成员--post data:'+JSON.stringify(data));
      const player_id = this.para('player_id') || null;
      const club_id = this.para('club_id') || null;
      // 用户
      const userInfo = await this.model('member').find(this.user.uid);
      
	  fly.config.timeout=10000;
	  fly.config.parseJson=true;
	  fly.interceptors.response.use(
			(response) => {
					        //只将请求结果的data字段返回
				return response.data
			},
			(err) => {
			//发生网络错误后会走到这里
			//return Promise.resolve("ssss")
			}
		)
	  console.log('邀请加入--playerid:'+player_id+' club_id:'+club_id);
	  var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=addClubMember&club_id='+club_id+'&obj_id='+player_id+'&sign=password';
	  console.log('邀请加入--url---------:'+url);
	  let ret = await fly.get(url).catch(() => false);
	  console.log('邀请加入 ret------------------:'+ret);
	  let retjson = (ret === false?null:JSON.parse(ret));
	  if (retjson!=null&&retjson.data.result==0) {
		  return this.success({name:'邀请加入成功！'});
	  }else{
		  //邀请加入 {"code":0,"data":{"clubId":10307,"command":"addClubMember","msg":"添加失败，请检查输入正确，并且不要重复添加","originCommand":"addClubMember","result":-7},"uid":334001}
		  return this.fail(retjson.data.msg);
	  }
    } else {
      // 获取用户信息
      const clubid = this.para('clubid') || null;
      this.assign('clubid', clubid);
      this.meta_title = '添加成员';
      if (this.isMobile) {
        this.active = 'club/player/index';
        return this.display(this.mtpl());
      } else {
        this.display();
      }
    }
  }
  
  // 俱乐部成员
  async playerAction() {
	if (this.isAjax('POST')) {
		const player_id = this.para('playerid') || null;
		const club_id = this.para('clubid') || null;
		const opt = this.para('opt') || null;
		const userInfo = await this.model('member').find(this.user.uid);
		
		fly.config.timeout=10000;
	    fly.config.parseJson=true;
	    fly.interceptors.response.use(
			(response) => {
					        //只将请求结果的data字段返回
				return response.data
			},
			(err) => {
			//发生网络错误后会走到这里
			//return Promise.resolve("ssss")
			}
		)
		
		if(opt==0){
			//设为管理员
			console.log('设为管理员--player_id:'+player_id+' club_id:'+club_id+' opt:'+opt);
	    	var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=setAdmin&club_id='+club_id+'&obj_id='+player_id+'&sign=password';
			console.log('设为管理员--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('设为管理员 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    
			if (retjson!=null&&retjson.data.result==0) {
		        return this.success({name:'设为管理员成功！'});
		    }else{
		    	return this.fail('设为管理员失败！');
		    }
		}else if(opt==1){
			//取消管理员
			console.log('取消管理员--player_id:'+player_id+' club_id:'+club_id+' opt:'+opt);
	    	var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=unsetAdmin&club_id='+club_id+'&obj_id='+player_id+'&sign=password';
			console.log('取消管理员--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('取消管理员 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    
			if (retjson!=null&&retjson.data.result==0) {
		        return this.success({name:'取消管理员成功！'});
		    }else{
		    	return this.fail('取消管理员失败！');
		    }
			
		}else if(opt==2){
			//删除俱乐部成员
			console.log('删除俱乐部成员--player_id:'+player_id+' club_id:'+club_id+' opt:'+opt);
	    	//var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=unsetAdmin&club_id='+club_id+'&obj_id='+player_id+'&sign=password';
			var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=removeClubMember&club_id='+club_id+'&obj_id='+player_id+'&sign=password';
			console.log('删除俱乐部成员--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('删除俱乐部成员 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    
			if (retjson!=null&&retjson.data.result==0) {
		        return this.success({name:'删除成员成功！'});
		    }else{
		    	return this.fail('删除成员失败！');
		    }
		}else if(opt==3){
			//入会同意
			const msg_id = this.para('msg_id') || '';
			console.log('同意入会--player_id:'+player_id+' club_id:'+club_id+' msg_id:'+msg_id+' opt:'+opt);
			var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=examineApply&club_id='+club_id+'&obj_id='+player_id+'&value=accept&msg_id='+msg_id+'&sign=password';
	    	console.log('入会同意--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('入会同意 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    
			if (retjson!=null&&retjson.data.result==0) {
		        return this.success({name:'同意入会成功！'});
		    }else{
		    	return this.fail('同意入会失败！');
		    }
		}else if(opt==4){
			const msg_id = this.para('msg_id') || '';
			console.log('拒绝入会--player_id:'+player_id+' club_id:'+club_id+' msg_id:'+msg_id+' opt:'+opt);
			var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=examineApply&club_id='+club_id+'&obj_id='+player_id+'&value=refuse&msg_id='+msg_id+'&sign=password';
	    	console.log('拒绝入会--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('拒绝入会 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    
			if (retjson!=null&&retjson.data.result==0) {
		    	// 同意入会
		        return this.success({name:'拒绝入会成功！'});
		    }else{
		    	return this.fail('拒绝入会失败！');
		    }
		}else if(opt==5){
			// 同意离会
			const msg_id = this.para('msg_id') || '';
			console.log('同意离会--player_id:'+player_id+' club_id:'+club_id+' msg_id:'+msg_id+' opt:'+opt);
			var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=examineQuit&club_id='+club_id+'&obj_id='+player_id+'&value=accept&msg_id='+msg_id+'&sign=password';
			console.log('同意离会--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('同意离会 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    
			if (retjson!=null&&retjson.data.result==0) {
		        return this.success({name:'同意离会成功！'});
		    }else{
		    	return this.fail('同意离会失败！');
		    }
		}else if(opt==6){
			
			// 拒绝离会
			const msg_id = this.para('msg_id') || '';
			console.log('拒绝离会--player_id:'+player_id+' club_id:'+club_id+' msg_id:'+msg_id+' opt:'+opt);
			var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=examineQuit&club_id='+club_id+'&obj_id='+player_id+'&value=refuse&msg_id='+msg_id+'&sign=password';
			console.log('拒绝离会--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('拒绝离会 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    
			if (retjson!=null&&retjson.data.result==0) {
		        return this.success({name:'拒绝离会成功！'});
		    }else{
		    	return this.fail('拒绝离会会失败！');
		    }
		}
		
	}else{
		const type = this.para('type') || 1;
	    const club_id = this.para('clubid') || null;
	    
	    const userInfo = await this.model('member').find(this.user.uid);
	    //var url ='http://47.97.119.70:5100/club?uid=334001&area=niuniuBackend&cmd=membersList&club_id=10307&obj_id=29&value=accept&msg_id=5b2f5b9453bb9c4f2c8eff62&sign=password';
	    fly.config.timeout=10000;
		fly.config.parseJson=true;
		fly.interceptors.response.use(
				    (response) => {
				        //只将请求结果的data字段返回
				        return response.data
				    },
				    (err) => {
				        //发生网络错误后会走到这里
				        //return Promise.resolve("ssss")
				    }
	     )
	    let clubmemberlist;
		let totalid =0;
		let owner_uid=0;
	    if(type==1){
	    	//会员列表
	    	var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=membersList&club_id='+club_id+'&sign=password';
	    	console.log('俱乐部成员--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('俱乐部成员 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    clubmemberlist = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.info.members))?retjson.data.info.members:[];
			owner_uid = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.info))?retjson.data.info.owner_uid:0;
			totalid = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.info.members))?retjson.data.info.members.length:0;
	    	for (const v of clubmemberlist) {
		          v.create_time = this.moment(v.joinDate).format('lll');
		          v.is_admin = think.isEmpty(v.isAdmin)?'':v.isAdmin.toString();
		          v.status =1;
		          v.head = (v.head.indexOf('defaultHead.jpg')!= -1)?'/static/mobile/img/defaultHead.jpg':v.head;
		    }
	    }else if(type==2){
	    	//入会申请列表
	    	var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=clubApplyList&club_id='+club_id+'&sign=password';
	    	console.log('俱乐部入会申请列表--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
	    	console.log('俱乐部入会申请 ret------------------:'+ret);
	    	let retjson = (ret === false?null:JSON.parse(ret));
	    	clubmemberlist = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.arr))?retjson.data.arr:[];
	    	totalid = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.arr))?retjson.data.arr.length:0;
	    	for (const v of clubmemberlist) {
		          v.create_time = this.moment(v.joinDate).format('lll');
		          ///static/mobile/img/logo.png
		          v.head = (v.head.indexOf('defaultHead.jpg')!= -1)?'/static/mobile/img/defaultHead.jpg':v.head;
		    }
	    }else if(type==3){
	    	//离会申请列表
//	    	返回值：
//	    	{
//	    		"code": 0,
//	    		"data": {
//	    			"arr": [{
//	    				"_id": "5bb78a9953bb9c4f2c5ccb97",	// 申请记录唯一标识
//	    				"admins": [334019],		// 管理员列表
//	    				"club_id": 10308,		// 俱乐部id
//	    				"create_time": "2018-10-06 00:00:25",	// 申请时间
//	    				"head": "res/image/defaultHead.jpg",	// 头像
//	    				"name": "游客fgh",		// 申请人昵称
//	    				"owner_uid": 334019,	// 群主游戏id
//	    				"status": "init",	// 申请状态：等待审批   done  同意   refuse  拒绝
//	    				"type": 1,
//	    				"uid": 334010
//	    			}],
//	    			"clubId": 10308,
//	    			"command": "clubApplyQuitList",
//	    			"msg": "",
//	    			"originCommand": "clubApplyQuitList",
//	    			"result": 0
//	    		},
//	    		"uid": 334019
//	    	}
	    	var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=clubApplyQuitList&club_id='+club_id+'&sign=password';
	    	console.log('俱乐部离会申请列表--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
	    	console.log('俱乐部离会申请 ret------------------:'+ret);
	    	let retjson = (ret === false?null:JSON.parse(ret));
	    	clubmemberlist = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.arr))?retjson.data.arr:[];
	    	totalid = (retjson!=null&&retjson.data.result==0&&!think.isEmpty(retjson.data.arr))?retjson.data.arr.length:0;
	    	for (const v of clubmemberlist) {
		          v.create_time = this.moment(v.joinDate).format('lll');
		          ///static/mobile/img/logo.png
		          v.head = (v.head.indexOf('defaultHead.jpg')!= -1)?'/static/mobile/img/defaultHead.jpg':v.head;
		    }
	    }
		
//	    this.assign('applynum', applynum);
//	    this.assign('leavenum', leavenum);
		this.assign('owner_uid', owner_uid);
	    this.assign('count', totalid);
	    this.assign('list', clubmemberlist);
	 // 当前位置
	    this.assign('type', type);
	    this.assign('clubid', club_id);
	    this.meta_title = '成员管理';
	    // 判断浏览客户端
	    if (this.isMobile) {
	      if (this.isAjax('get')) {
	    	  console.log('俱乐部成员 ------------------1:');
	        return this.json(clubmemberlist);
	      } else {
	    	  console.log('俱乐部成员 ------------------2:');
	        this.active = 'club/index';
	        return this.display(this.mtpl());
	      }
	    } else {
	    	console.log('俱乐部成员 ------------------3:');
	      return this.display();
	    }
	}
  }
  
//查找我的玩家
  async searchplayerAction() {
	    const player_id = this.para('playerId') || null;
	    console.log('player_id ---------:'+player_id);
	   
	    fly.config.timeout=10000;
	    fly.config.parseJson=true;
	    fly.interceptors.response.use(
			(response) => {
					        //只将请求结果的data字段返回
				return response.data
			},
			(err) => {
			//发生网络错误后会走到这里
			//return Promise.resolve("ssss")
			}
		)
		var data ={};
		console.log('查询玩家信息--player_id:'+player_id);
	    var url = 'http://47.97.119.70:5166/GameSupport/dn?cmd=getPlayerByUid&uid='+player_id+'&sign=password';
		console.log('查询玩家信息--url---------:'+url);
	    let ret = await fly.get(url).catch(() => false);
		console.log('查询玩家信息 ret------------------:'+ret);
		let retdata = (ret === false?null:JSON.parse(ret));
		//{"data":{"command":"getPlayerByUid","msg":"玩家不存在","originCommand":"getPlayerByUid",
		//"result":-2},"uid":22}
		if(retdata!=null){
			if(retdata.data.result==0){
				data = retdata.data.info;
				data.headimgurl = (data.headimgurl.indexOf('defaultHead.jpg')!= -1)?'/static/mobile/img/defaultHead.jpg':data.headimgurl;
				return this.success(data);
			}else{
				return this.fail(retdata.data.msg);
			}
		}else{
			return this.fail('玩家不存在');
		}
  }
  
//俱乐部账户
  async accountAction() {
	if (this.isAjax('POST')) {
		const club_id = this.para('clubid') || null;
		const opt = this.para('opt') || null;
//        const userInfo = await this.model('member').find(this.user.uid);
		
		fly.config.timeout=10000;
	    fly.config.parseJson=true;
	    fly.interceptors.response.use(
			(response) => {
					        //只将请求结果的data字段返回
				return response.data
			},
			(err) => {
			//发生网络错误后会走到这里
			//return Promise.resolve("ssss")
			}
		)
		
		if(opt==-1){
			//解散俱乐部
			console.log('解散俱乐部-- club_id:'+club_id+' opt:'+opt);
	    	//var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=setAdmin&club_id='+club_id+'&obj_id='+player_id+'&sign=password';
			var url ='http://www.hongshihuyu.com:17100/';
			console.log('解散俱乐部--url---------:'+url);
	    	let ret = await fly.get(url).catch(() => false);
			console.log('解散俱乐部 ret------------------:'+ret);
		    let retjson = (ret === false?null:JSON.parse(ret));
		    
			if (retjson!=null&&retjson.data.result==0) {
		        return this.success({name:'解散俱乐部成功！'});
		    }else{
		    	return this.fail('解散俱乐部失败！');
		    }
		}
		
	}else{
		const club_id = this.para('clubid') || null;
//		const cardNum = this.para('cardNum') || 0;
//		const name = this.para('name') || '';
	    // 筛选
		var cardNum =0;
		var dailyCard =0;
		var warnCard = 0;
		var name ='';
		const userInfo = await this.model('member').find(this.user.uid);
		
		fly.config.timeout=10000;
	    fly.config.parseJson=true;
	    fly.interceptors.response.use(
			(response) => {
					        //只将请求结果的data字段返回
				return response.data
			},
			(err) => {
			//发生网络错误后会走到这里
			//return Promise.resolve("ssss")
			}
		)
		var url ='http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=queryClubDetail&club_id='+club_id+'&sign=password';
		console.log('俱乐部详细信息--url---------:'+url);
	    let ret = await fly.get(url).catch(() => false);
		console.log('俱乐部详细信息 ret------------------:'+ret);
		let retjson = (ret === false?null:JSON.parse(ret));
		if (retjson!=null&&retjson.data.result==0) {
			cardNum = retjson.data.info.cardNum;
			name = retjson.data.info.name;
			dailyCard = retjson.data.info.dailyCard;
			warnCard = retjson.data.info.warnCard;
	    }
		console.log('俱乐部详细信息 warnCard------------------:'+warnCard);
		console.log('俱乐部详细信息 dailyCard------------------:'+dailyCard);
	    this.assign('club_id', club_id);
	    this.assign('cardNum', cardNum);
	    this.assign('warnCard', warnCard);
	    this.assign('dailyCard', dailyCard);
	    
	    this.assign('name', name);
	    this.assign('card_count', userInfo.card_count);
	    this.meta_title = '俱乐部账户';
	    // 判断浏览客户端
	    if (this.isMobile) {
	      if (this.isAjax('get')) {
//	        for (const v of data.data) {
//	          v.create_time = this.moment(v.create_time).format('lll');
//	        }
	        return this.json(data);
	      } else {
	        this.active = 'center/club/index';
	        return this.display(this.mtpl());
	      }
	    } else {
	      return this.display();
	    }
	}
  }
  
//编辑俱乐部名字
  async renameAction() {
		if (this.isAjax('POST')) {
			const data = this.post();
			console.log('编辑俱乐部名字--post data:'+JSON.stringify(data));
			const club_id = this.para('clubid') || null;
			
			const userInfo = await this.model('member').find(this.user.uid);
			
			fly.config.timeout=10000;
		    fly.config.parseJson=true;
		    fly.interceptors.response.use(
				(response) => {
						        //只将请求结果的data字段返回
					return response.data
				},
				(err) => {
				//发生网络错误后会走到这里
				//return Promise.resolve("ssss")
				}
			)
			
		     //编辑俱乐部名字
			console.log('编辑俱乐部名字--: club_id:'+club_id);
		    //var url = 'http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=setAdmin&club_id='+club_id+'&obj_id='+player_id+'&sign=password';
			var url ='http://www.hongshihuyu.com:17100/club?uid='+userInfo.game_id+'&area=niuniuBackend&cmd=modifyClub&club_id='+club_id+'&name='+data.club_name+'&notice=&sign=password';
		    console.log('编辑俱乐部名字--url---------:'+url);
		    let ret = await fly.get(encodeURI(url)).catch(() => false);
			console.log('编辑俱乐部名字 ret------------------:'+ret);
			let retjson = (ret === false?null:JSON.parse(ret));
		    if (retjson!=null&&retjson.data.result==0) {
			        return this.success({name:'编辑名字成功！'});
			}else{
			    	return this.fail('编辑名字失败！');
			}
		}
	  }
  
   //转入房卡
  async rechangeAction() {
		if (this.isAjax('POST')) {
			const data = this.post();
			console.log('转入房卡--post data:'+JSON.stringify(data));
			const club_id = this.para('club_id') || null;
			if (think.isEmpty(data.card_num)) {
		        return this.fail('转入房卡数不能为空！');
		    } 
			if (think.isEmpty(club_id)) {
		        return this.fail('俱乐部ID不能为空！');
		    }
			
			const userInfo = await this.model('member').find(this.user.uid);
			
			fly.config.timeout=10000;
		    fly.config.parseJson=true;
		    fly.interceptors.response.use(
				(response) => {
						        //只将请求结果的data字段返回
					return response.data
				},
				(err) => {
				//发生网络错误后会走到这里
				//return Promise.resolve("ssss")
				}
			)
			
		     //转入房卡
			console.log('转入房卡--: club_id:'+club_id);
		    var url ='http://47.97.119.70:5166/GameSupport/dn?cmd=addClubCard&clubId='+club_id+'&value='+data.card_num+'&sign=password'
			console.log('转入房卡--url---------:'+url);
		    let ret = await fly.get(encodeURI(url)).catch(() => false);
			console.log('转入房卡 ret------------------:'+ret);
			let retjson = (ret === false?null:JSON.parse(ret));
		    if (retjson!=null&&retjson.data.result==0) {
		    	const update = await this.model('member').where({id:this.user.uid}).decrement('card_count', data.card_num);
		  		
		    	//0:账户充值，1:提现,2:订单,3:充卡,4:充币,5:返利,6:奖励金币，7:奖励房卡,8:耗卡,9:耗币
		    	if(update){
		    		const blog = {
		   	                 admin_id: 1,
		   	                 user_id: this.user.uid,
		   	                 type:8,
		   	                 time: new Date().valueOf(),
		   	                 amount: Number(data.card_num),
		   	                 amount_log: Number(userInfo.card_count)-Number(data.card_num),
		   	                 note: userInfo.username+'俱乐部:'+club_id+' 转入房卡 '+data.card_num+' 张'
		   	               };
		   	        await this.model('balance_log').add(blog);
		    	}
	            
		    	return this.success({name:'转入房卡成功！'});
			}else{
			    return this.fail('转入房卡失败！');
			}
		}
	  }
};